<template>
  <div class="layout">
    <div class="main">
      <div class="userName">你不是{{userName}}?点我<span @click="backToLogin()">切换账号</span></div>
      <p class="title">{{userName}}，{{timeQuantum}}，欢迎使用</p>
      <p><a class="deal-search" @click="toServiceList" href="javascript:;"><img src="../assets/img/ico-deal.png" alt=""></a><span>服务日记</span></p>
      <p><a class="listing-search" @click="toPasswordList" href="javascript:;"><img src="../assets/img/ico-listing.png" alt=""></a><span>动态密码获取</span></p>
    </div>
    <p class="footer">©2017 上海家后信息科技有限公司</p>
  </div>
</template>
<script>
  import { EMPLOYEE_KEY, USER_NAME } from '../assets/js/config'
  import cache from '../assets/js/cache'
  export default {
    name: 'index',
    data () {
      return {
        userName: '',
        timeQuantum: ''
      }
    },
    created () {
      let token = cache.get(EMPLOYEE_KEY)
      let userName = cache.get(USER_NAME)
      if (token === null || userName === null) {
        this.$router.push({ path: '/' })
      }
      this.userName = userName
      let houses = new Date().getHours()
      if (houses > 6 && houses < 8) {
        this.timeQuantum = '早上好'
      } else if (houses >= 8 && houses < 12) {
        this.timeQuantum = '上午好'
      } else if (houses >= 12 && houses < 13) {
        this.timeQuantum = '中午好'
      } else if (houses >= 13 && houses < 19) {
        this.timeQuantum = '下午好'
      } else if (houses >= 19 && houses < 23) {
        this.timeQuantum = '晚上好'
      } else {
        this.timeQuantum = '深夜了'
      }
    },
    methods: {
      toServiceList () {
        this.$router.push({ path: '/serviceListByHouseNumber' })
      },
      toPasswordList () {
        this.$router.push({ path: '/passwordList' })
      },
      backToLogin () {
        cache.del(EMPLOYEE_KEY)
        cache.del(USER_NAME)
        this.$router.push({ path: '/' })
      }
    }
  }
</script>
<style scoped>
  .layout {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    background: url("../assets/img/indebg.png") center center no-repeat;
    background-size: 100% 100%;
    -webkit-background-size: 100% 100%;
    overflow: hidden;
    position: relative;
  }
  .main {
    width: 90%;
    padding-bottom: 1.8rem;
    background: url("../assets/img/hangbg.png") center center no-repeat;
    -webkit-background-size: cover;
    background-size: cover;
    position: absolute;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%,-50%);
    -moz-transform: translate(-50%,-50%);
    -ms-transform: translate(-50%,-50%);
    -o-transform: translate(-50%,-50%);
    transform: translate(-50%,-50%);
  }
  .main > .userName {
    position: absolute;
    top:-1rem;
    left: 0;
    height: .8rem;
    line-height:.8rem;
    padding-right:5%;
    width:95%;
    text-align: right;
    font-size:.28rem;
  }
  .main > div >span{
    color:#fff;
    float: right;
  }
  .main > p {
    padding-top: .8rem;
  }
  .main > .title {
    height: 1rem;
    line-height: 1rem;
    padding-top: .96rem;
    font-size: .36rem;
    text-align: center;
    color: #404040;
  }
  .main > p > a {
    height: 2rem;
    width: 2rem;
    line-height: 2rem;
    border-radius: .1rem;
    margin: 0 auto;
    display: block;
    font-size: .4rem;
    text-align: center;
    color: #fff;
  }
  .main > p > span {
    display: block;
    margin: .3rem auto 0;
    text-align: center;
    color: #555;
    font-size: .32rem;
  }
  .footer {
    position: absolute;
    width: 100%;
    left:0;
    bottom:5%;
    text-align: center;
    color: #fff;
  }
</style>
